import random

def guess_number_game():
    # 生成1到100之间的随机数
    secret_number = random.randint(1, 100)
    max_attempts = 7
    attempts = 0
    
    print("欢迎来到猜数字游戏！")
    print(f"我已经想好了一个1到100之间的数字，你有{max_attempts}次机会猜出它")
    
    while attempts < max_attempts:
        # 计算剩余次数
        remaining = max_attempts - attempts
        
        # 获取玩家输入并验证
        try:
            guess = input(f"请输入你的猜测（剩余{remaining}次）：")
            guess = int(guess)
            
            # 检查输入是否在有效范围内
            if guess < 1 or guess > 100:
                print("请输入1到100之间的数字！")
                continue
                
            attempts += 1
            
            # 判断猜测结果
            if guess < secret_number:
                print("太小了！再试一次")
            elif guess > secret_number:
                print("太大了！再试一次")
            else:
                print(f"恭喜你！你猜对了！答案就是{secret_number}")
                print(f"你用了{attempts}次就猜对了")
                return
                
        except ValueError:
            print("请输入有效的数字！")
    
    # 如果用完所有机会仍未猜对
    print(f"很遗憾，你已经用完了所有{max_attempts}次机会")
    print(f"正确答案是：{secret_number}")

# 启动游戏
if __name__ == "__main__":
    guess_number_game()